import time
from threading import Thread, Event
import sys
from common.utility import Utility

# 主函数
def main(thread_count: int = 500):
    global event
    Utility.print_info('entered.')
    event = Event()
    Utility.print_info(f'event is { event.is_set() }.')
    threads: list[Thread] = []
    for i in range(thread_count):
        threads.append(start_thread())
    time.sleep(1)
    event.set()
    Utility.print_info(f'event is { event.is_set() }, then exited.')

# 创建线程
def start_thread() -> Thread:
    thread: Thread = Thread(target=task)
    thread.start()
    return thread

# 任务
def task() -> None:
    global event
    Utility.print_info('entered.')
    event.wait()
    Utility.print_info('exited.')

print(f'is gil enabled: {sys._is_gil_enabled()}')
print(f'python version: {sys.version}')
event: Event
main(5)
